
class Solution {
    public int pivotInteger(int n) {
        // 遍历
        for (int i = 1; i <= n; i++) {
            if (getSum(1, i) == getSum(i, n)) {
                return i;
            }
        }
        return -1;
    }
    
    // 用于计算累加
    public int getSum(int startNum, int endNum) {
        int sum = 0;
        for (int i = startNum; i <= endNum; i++) {
            sum += i;
        }
        return sum;
    }
}

